package com.heima.api.config;

import com.heima.api.client.fallback.ItemClientFallback;
import com.hmall.common.utils.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;

/**
 * @author gonghuaiguo
 */
public class DefaultFeignConfig {

    @Bean
    public Logger.Level feignLogLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor requestInterceptor(){
        return template -> {
           // 获取登录用户信息
            Long user = UserContext.getUser();
            if(user == null) return;
            //如果不为空则放入请求头中，传递给下游服务
            template.header("user-info",user.toString());
        };
    }

    @Bean
    public ItemClientFallback itemClientFallback(){
        return new ItemClientFallback();
    }
}
